<template>
  <uni-notice-bar v-show="this.barShow" scrollable showGetMore single text="您未绑定学号，请点击右侧进行绑定"
                  @getmore="uni.navigateTo({url: 'bindStu'})"></uni-notice-bar>

  <uni-card :extra="this.user.class" :sub-title="'学号：' + user.stuId" :thumbnail="user.avatar"
            :title="user.userName">

  </uni-card>

</template>

<script>
import {getInfo, logout} from "@/api/login";
import {getStu} from "@/api/student";
import {getClass} from "../../api/class";

export default {
  components: {},
  data() {
    return {
      user: {
        userId: 0,
        userName: "",
        email: "",
        phonenumber: "",
        sex: "0",
        avatar: "",
        loginIp: "",
        loginDate: "",
        stuId: null,
        class: ""
      },
      barShow: true,
    }
  },
  methods: {},
  created() {
    getInfo().then(res => {
      this.user = res.user
      this.user.avatar = this.user.avatar || "http://159.138.0.68//static/img/profile.8ea50b80.jpg"
      this.user.stuId || uni.showToast({title: "请绑定学号，不然您无法使用预约功能", icon: 'error'})
      this.barShow = !this.user.stuId
      !this.user.stuId || getStu(this.user.stuId).then(res => {
        this.user.stuRealName = res.data.stuRealName
        getClass(res.data.stuClass).then(res => {
          this.user.class = res.data.className
        })
      })
    })
  },
  onShow(options) {
  },
  onPullDownRefresh() {
    logout().then()
    uni.stopPullDownRefresh()
  }
}
</script>

<style>
</style>
